package com.g001.enums;

public enum MovingBlockType {
	/**
	 * x ++ / y ++ 3
	 * x ++ / y -- 2
	 * x -- / y -- 1 
	 * x -- / y ++ 0 
	 * x / y ++
	 * x / y --
	 * x ++ / y
	 * x -- / y
	 */
	
	XP_YP(0), // x ++ / y ++
	XP_YN(1), // x ++ / y -- 
	XN_YN(2), // x -- / y -- 
	XN_YP(3), // x -- / y ++ 
	X_YP(4),
	X_YN(5),
	Y_XP(6),
	Y_XN(7),
	X_Y(8); // neutral - no move
	
	private int id;
	
	MovingBlockType(final int id){
		this.id = id;
	}
	
	public static MovingBlockType getMovingBlockType(final int id){
		switch(id){
			case 0 : return XP_YP;
			case 1 : return XP_YN;
			case 2 : return XN_YN;
			case 3 : return XN_YP;
			case 4 : return X_YP;
			case 5 : return X_YN;
			case 6 : return Y_XP;
			case 7 : return Y_XN;
			case 8 : return X_Y;
			default: new IllegalArgumentException("The MovingBlockType id '"+id+"' is not associated to any MovingBlockType.");
		}
		return null;
	}
	
	public static MovingBlockType getMovingBlockType(final float x, final float y, final float xDest, final float yDest){
		
		if(x<xDest) {
			if(y == yDest) return Y_XP;
			if(y<yDest) {
				return XP_YP;
			} else {
				return XP_YN;
			}
		} else if(x>xDest){
			if(y == yDest) return Y_XN;
			if(y<yDest) {
				return XN_YP;
			} else {
				return XN_YN;
			}
		} else { // if(x==xDest)
			if(y == yDest) return X_Y;
			if(y<yDest) {
				return X_YP;
			} else {
				return X_YN;
			}
		} 
	 
	}

}
